#include <inttypes.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include "common/timestamp.h"
#include "uorc/uorc.h"

/* Example program that retreives and prints the irsensor value
 *
 * This program periodically prints a float representing the voltage
 * read from a port on the orcboard (should be in [0, 5]V).
 */

int main(int argc, char *argv[])
{
    ///// uorc /////
    uorc_t *uorc = uorc_create();
    if (uorc == NULL) {
        printf("ERR: Could not create orc\nExiting...\n");
        exit(-1);
    }

    uorc_status_t status;

    while(1) {
        usleep(100000);  // ~10 Hz

        uorc_get_status(uorc, &status);
        float v = uorc_get_analog_voltage(&status, 0);  // port 0
        printf("%"PRIu64" %15f\n", timestamp_now(), v);
    }

    uorc_destroy(uorc);
}
